/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import pojo.HangVePOJO;

/**
 *
 * @author b2
 */
public class HangVeDAO {

    public static ArrayList<HangVePOJO> LayDanhSachDangVe() {
        ArrayList<HangVePOJO> ds = new ArrayList<HangVePOJO>();
        try {

            String sql = "SELECT * FROM HANGVE";
            MySqlDataAccessHelper helper = new MySqlDataAccessHelper();
            helper.open();
            ResultSet rs = helper.executeQuery(sql);
            while (rs.next()) {
                HangVePOJO hv = new HangVePOJO();
                hv.setMaHangVe(rs.getString("MaHangVe"));
                hv.setTenHangVe(rs.getString("TenHangVe"));
                ds.add(hv);
            }
            helper.close();

        } catch (SQLException ex) {
            Logger.getLogger(HangVeDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return ds;
    }

    public static HangVePOJO LayDangVe(String maHangVe) {
        HangVePOJO hv = new HangVePOJO();
        try {

            String sql = "SELECT * FROM HANGVE WHERE MAHANGVE = '" + maHangVe + "'";
            MySqlDataAccessHelper helper = new MySqlDataAccessHelper();
            helper.open();
            ResultSet rs = helper.executeQuery(sql);
            while (rs.next()) {
                hv.setMaHangVe(rs.getString("MaHangVe"));
                hv.setTenHangVe(rs.getString("TenHangVe"));
            }
            helper.close();

        } catch (SQLException ex) {
            Logger.getLogger(HangVeDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return hv;
    }
}
